/**
 * Copyright 2009-2011 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.myjung.model;

import java.util.ArrayList;
import java.util.List;

import net.myjung.model.annotation.MdlAttribute;

import org.springframework.util.StringUtils;

/**
 * @author Steve M. Jung
 */
@SuppressWarnings("serial")
public class Query extends Filters {
	@MdlAttribute
	private int pageIndex = 0;
	@MdlAttribute
	private int pageSize = -1;
	private List<String> group;
	private List<Order> order;
	public int getPageIndex() {
		return pageIndex;
	}
	public void setPageIndex(int pageNo) {
		this.pageIndex = pageNo;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public List<String> getGroup() {
		return group;
	}
	public void setGroup(List<String> group) {
		this.group = group;
	}
	public List<Order> getOrder() {
		return order;
	}
	public void addGroup(String group) {
		if (this.group == null)
			this.group = new ArrayList<String>();
		this.group.add(group);
	}
	public void setOrder(List<Order> orders) {
		this.order = orders;
	}
	public void addOrder(Order order) {
		if (this.order == null)
			this.order = new ArrayList<Order>();
		this.order.add(order);
	}
	public void addOrder(String field, boolean asc) {
		if (field.contains(",")) {
			String[] fs = StringUtils.tokenizeToStringArray(field, ",");
			for (String f : fs)
				addOrder(new Order(f, asc));
		} else {
			addOrder(new Order(field, asc));
		}
	}
}